<template>
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

  <el-form-item label="账号" prop="username">
    <el-input type="text" v-model="ruleForm.username" :disabled="true" ></el-input>
  </el-form-item>
  <el-form-item label="年龄" prop="age">
    <el-input v-model.number="ruleForm.age"></el-input>
  </el-form-item>
  <el-form-item label="姓名" prop="name">
    <el-input v-model="ruleForm.name"></el-input>
  </el-form-item>
  <el-form-item label="手机号" prop="phone">
    <el-input type="text" v-model="ruleForm.phone" autocomplete="off"></el-input>
  </el-form-item>


<el-form-item>
  <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>

</el-form-item>
</el-form>


</template>
<script>
export default {
  created() {
    var th = this
    axios({
      url:'http://82.156.197.128:8085/user/findMessage',
      method:"POST"
    }).then((resp)=>{
      console.log(resp.data);
      th.ruleForm=resp.data;
    })
  },
  data() {
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('年龄不能为空'));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error('请输入数字值'));
        } else {

            callback();

        }
      }, 1000);
    };

    return {
      ruleForm: {
        username:'',
        name:'',
        phone:'',
        age: 0
      },
      rules: {
        age: [
          { validator: checkAge, trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios({
            url:"http://82.156.197.128:8085/user/ChangeMessage",
            method:"POST",
            params:{
              "name":this.ruleForm.name,
              "age":this.ruleForm.age,
              "phone":this.ruleForm.phone
            }
          }).then((resp)=>{
          this.$notify.success({
            title:"成功",
            message:"信息修改成功~"
          })
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  }
}
</script>